	var page_num = 0;
	var page_limit = 5;
	
	var data = [];
	
	var localData;
	
	window.onload = function(){
	
	
		selDownList()
		
	}
	
	function show(){

		localData = JSON.parse(sessionStorage.getItem("download"));
		data = [];
		for (let i = 0; i < localData.length; i++) {
			data.push(localData[i]);
		}

		//获取ID
			var file_list = document.getElementById("list");
			file_list.innerHTML = "";
			for (let i = 0; i < data.length; i++) {
				let tr = document.createElement("tr");
				if(i > 4){
					tr.setAttribute("style","display:none;")
				}
				let td = document.createElement("td");
				let input = document.createElement("input");
				input.setAttribute("type", "checkbox");
				input.setAttribute("style", "opacity: 1;margin-left: 5px;position: unset;")
		
		
				let td2 = document.createElement("td");
				let text2 = document.createTextNode(data[i].file_name);
				let input2 = document.createElement("input");
				input2.setAttribute("type", "hidden");
				input2.setAttribute("value", data[i].id + "")
				td2.appendChild(text2);
		
				let td3 = document.createElement("td");
				let span = document.createElement("span");
				span.setAttribute("class", "text-muted");
		
				
		let img = document.createElement("i");
				img.setAttribute("class", "fa fa-clock-o");
				let spanText = document.createTextNode(new Date(data[i].file_time));
				span.appendChild(img);
				span.appendChild(spanText);
		
				
		td3.appendChild(span);
		
				let td4 = document.createElement("td");
				let td4span = document.createElement("span");
		
				td4span.setAttribute("class", "badge badge-pill badge-danger");
				let text4 = document.createTextNode(data[i].file_size);
				td4span.appendChild(text4)
				td4.appendChild(td4span);
		
				
				let td5 = document.createElement("td");
				
				let btn3 = document.createElement("button");
				btn3Text = document.createTextNode("取消");
				btn3.setAttribute("onclick", "Del(this)");
				
				//类型
				let td6 = document.createElement("td");
				let td6span = document.createElement("span");
				td6span.setAttribute("class", "badge badge-pill badge-danger");
				let text6;
				if(data[i].type == 0){
					text6 = document.createTextNode("下载");
				}else{
					
				     text6 = document.createTextNode("上传");
				}
				td6span.appendChild(text6)
				td6.appendChild(td6span);
					
					
				//状态
					
				let td7 = document.createElement("td");
				let td7span = document.createElement("span");
				td6span.setAttribute("class", "badge badge-pill badge-danger");
				let text7;
				if(data[i].status == 0){
					text7 = document.createTextNode("传输中");
				}else if(data[i].status == 1){
					
						text7 = document.createTextNode("已完成");
				}else{
					
				     text6 = document.createTextNode("已取消");
				}
				td7span.appendChild(text7)
				
				td7.appendChild(td7span);
				
				
				
				btn3.appendChild(btn3Text);
				btn3.setAttribute("class", "waves-effect waves-light btn btn-info btn-xs ");
		
				td5.appendChild(btn3);
		
				td.appendChild(input2);
				td.appendChild(input);
				tr.appendChild(td);
				tr.appendChild(td2);
				tr.appendChild(td3);
				tr.appendChild(td4);
				tr.appendChild(td6);
				tr.appendChild(td7);
				tr.appendChild(td5);
				file_list.appendChild(tr);
		
			}
		pagelist()
		page_show(page_num)
	}
				

	


function Del(a) {

	let id = a.parentNode.parentNode.firstElementChild.firstElementChild.value;

	for (let i = 0; i < data.length; i++) {

		if (data[i].id == id) {
			data.splice(i, 1);

		}
	}
	let s = JSON.stringify(data);
	sessionStorage.setItem("download", s);
	alert("取消成功");
	 show()
}


function DelAll() {

	let list = document.getElementById("list").children;
	var count = 0;
	var length = data.length;
	for (let i = 0; i < list.length; i++) {
		let checkedTags = list[i].firstElementChild.lastElementChild
		//如果第一个字段的状态时true
		if (checkedTags.checked == true) {
			//查找对应的id
			let id = checkedTags.parentElement.firstElementChild.value;
			// console.log(id);
			for (let i = 0; i < data.length; i++) {

				if (data[i].id == id) {
					data.splice(i, 1);
					i--;
				}
			}
		} else {
			count++;
		}

	}
	// console.log(count);
	// console.log(data.length);

	if (count == length) {
		alert("请选择要取消的任务")
	} else {
		let s = JSON.stringify(data);
		sessionStorage.setItem("download", s);

		alert("批量取消成功");
		show()
	}

}


//分页
function pagelist(){
	
	let page_top_num = page_num-1;
	if(page_top_num < 0){
		page_top_num = 0;
	}
	
	let page_down_num = page_num+1;
	
	// console.log(page_top_num);
	// console.log(page_down_num);
	//获取长度
	let length = JSON.parse(sessionStorage.getItem("download")).length;

	let page = document.getElementById("page_list");
	// console.log(length)
	// <li class="paginate_button page-item ">
	// <a href="#" aria-controls="complex_header" data-dt-idx="2" tabindex="0" class="page-link">2</a>
	// </li>
	//插入上一页
	let str  =  `<li class="paginate_button page-item previous" id="complex_header_previous">
								<a href="#" aria-controls="complex_header" data-dt-idx="0" tabindex="0"
									class="page-link" onclick="page_show(${page_top_num})">Previous</a>
							</li>`;
	for (var i = 0; i < length/5; i++) {
		//创建li
		// let li = document.createElement("li");
		// li.setAttribute("class","paginate_button page-item");
		// let a = document.createElement("a");
		// a.setAttribute("class","page-link")
		// let a_text = document.createTextNode(i+1);
		// a.appendChild(a_text);
		// li.appendChild(a);
		// page.appendChild(li);
		
		
		if(page_num == i ){
			
			str += `<li class="paginate_button page-item active">`;
		}else{
			str += `<li class="paginate_button page-item">`;
		}
		
		str += `
					<a href="#" onclick="page_show(${i})" aria-controls="complex_header" data-dt-idx="6" tabindex="0" class="page-lin">${i+1}</a>
				</li>`;
	}
	//插入下一页
	str  += `<li class="paginate_button page-item next" id="complex_header_next">
						<a href="#" aria-controls="complex_header" data-dt-idx="7" tabindex="0"
								class="page-link" onclick="page_show(${page_down_num})">Next</a>
						</li>`;
	page.innerHTML = str;
}


function page_show(a){
// if(type = 0){
// 	a = a - 1;
// 	if(a < 0){
// 		a =0;
// 	}
// }else{
// 	a = a + 1; 
// }


//判断是否超过最大页数
//获取长度
let length = JSON.parse(sessionStorage.getItem("download")).length;
if(a >= length/page_limit){
	alert("已经是最后一页了")
	return;
}
// 获取id 
let list = document.getElementById("list");
//获取子类
let listNew = list.children;

//起始位置等于 页数 乘以每页数量-1

let star_num = a * page_limit;
let end_num = 0;
if(star_num < 0){
	star_num = 0;
	end_num = page_limit;
}else{
	end_num = star_num + page_limit +1;
}

// 显示提示信息 获取ID

let complex_header_info = document.getElementById("complex_header_info");
complex_header_info.innerHTML = '';
let tip = "Showing "+(star_num+1)+" to "+end_num +" of "+length+" entries"
let text = document.createTextNode(tip);
complex_header_info.appendChild(text);


for (let i = 0; i < listNew.length; i++) {
	if(i >=star_num && i <(star_num+page_limit) ){
		//设置属性为可见
		listNew[i].setAttribute("style","");
	}else{
		listNew[i].setAttribute("style","display:none");
	}
	
}
page_num = a;
// console.log("翻页后"+a);
pagelist();
}

